﻿using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace System.Data {
    public interface IRepository<TEntity> where TEntity : Entity {
        IDbSession DBA { get; }
        string TableName { get; }

        #region Insert
        TEntity Add(TEntity model);
        void Add(List<TEntity> models);
        TEntity AddOrUpdate(TEntity model);
        #endregion

        #region Update
        TEntity Update(TEntity model);
        void Update(List<TEntity> models);
        /// <summary>
        /// 表主键必须是ID
        /// </summary>
        /// <param name="keyId">ID</param>
        /// <param name="fieldName">字段名</param>
        /// <param name="fieldValue">字段值</param>
        /// <returns></returns>
        bool UpdateField(string keyId,string fieldName,string fieldValue);
        #endregion

        #region Delete
        void Delete(TEntity model);
        /// <summary>
        /// 表主键必须是ID
        /// 批量删除数据 1,2,3
        /// </summary>
        bool Delete(string Idlist);
        bool Delete(Expression<Func<TEntity,bool>> predicate);
        bool Delete(List<TEntity> models);
        bool DeleteWhere(string sqlWhere);
        #endregion

        #region Exists
        bool Exists(string id);
        bool Exists(ISpecification<TEntity> specification);
        bool Exists(Expression<Func<TEntity,bool>> predicate);
        #endregion

        #region Find
        TEntity Find(string id);
        TEntity Find(Expression<Func<TEntity,bool>> predicate);
        TEntity Find(ISpecification<TEntity> specification);
        #endregion

        #region FindAll
        IQueryable<TEntity> FindAll();
        IQueryable<TEntity> FindAll(Expression<Func<TEntity,bool>> predicate);
        IQueryable<TEntity> FindAll(string sqlWhere);
        JQridPageData FindAll(Paging paging);
        IQueryable<TEntity> FindAll(string sqlWhere,string orderby = "",int startIndex = 1,int endIndex = 10);
        #endregion
    }
}